package com.nolon.flange.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.nolon.flange.model.RawInfo

@Dao
interface RawInfoDao {

    @Insert
    suspend fun insert(rawInfo: RawInfo): Long

    @Insert
    suspend fun insertAll(rawInfos: List<RawInfo>)

    @Delete
    suspend fun delete(rawInfo: RawInfo)

    @Update
    suspend fun update(rawInfo: RawInfo)

    @Query("SELECT * FROM raw_info_table WHERE raw_id = :id")
    suspend fun getRaw(id: Int): RawInfo


    @Query("SELECT * FROM raw_info_table WHERE raw_project_id = :projectId")
    fun getAllByProjectId(projectId: Int): LiveData<List<RawInfo>>

    @Query("DELETE  FROM raw_info_table WHERE raw_id = :id ")
    suspend fun deleteById(id: Int)

    @Query("DELETE  FROM raw_info_table WHERE raw_project_id = :projectId")
    suspend fun deleteAllByProjectId(projectId: Int)

    @Query("DELETE  FROM raw_info_table WHERE raw_project_id = :projectId")
    suspend fun deleteAllByProjectIdAndOrderId(projectId: Int)

    @Query("SELECT * FROM raw_info_table WHERE raw_project_id = :projectId")
    fun getRawsByProjectId(projectId: Int): LiveData<List<RawInfo>>

}
